const getId = () => ((1 + Math.random()) * 0x10000000 || 0).toString(16).substring(1)
const useDialogStore = defineStore(
  'dialog',
  {
    state: () => ({
      dialogList: [],
      dialogComponents: []
    }),
    actions: {
      initDialog(option) {
        this.dialogComponents.push(...option)
      },
      openDialog(option) {
        option.id = getId()
        this.dialogList.push(option)
      },
      closeDialog(val, type) {
        switch (type) {
          case 'id':
            this.dialogList = this.dialogList.filter((item) => item.id !== val)
            break
          case 'name':
            this.dialogList = this.dialogList.filter((item) => item.name !== val)
            break
          default:
            this.dialogList = []
        }
      }
    }
  }
)

export default useDialogStore